package com.lagou.boot;

import com.lagou.client.RPCConsumer;
import com.lagou.request.RpcRequest;
import com.lagou.service.IUserService;

import java.util.UUID;

public class ConsumerBoot {

    //参数定义
    private static final String PROVIDER_NAME = "UserService#sayHello#";

    public static void main(String[] args) throws InterruptedException {

        //1.创建代理对象
//        IUserService service = (IUserService) RPCConsumer.createProxy(IUserService.class);

        //2.循环给服务器写数据
       /* while (true){
            String result = service.sayHello("are you ok !!");
            System.out.println(result);
            Thread.sleep(2000);
        }*/
        IUserService userService = (IUserService)RPCConsumer.createProxy(IUserService.class);

        while (true){
            RpcRequest rpcRequest = new RpcRequest();
            rpcRequest.setRequestId(UUID.randomUUID().toString());
            rpcRequest.setClassName("aaa.bbb.ccc");
            rpcRequest.setMethodName("init");
            rpcRequest.setParameters(new Object[]{"hhh",999});
            rpcRequest.setParamterTypes(new Class[]{int.class,Void.class,Enum.class});

            System.out.println("客户端入参为："+rpcRequest.toString());
            String result = userService.sayHello(rpcRequest);
            System.out.println("客户端接收到服务器端的出参为："+result);
            Thread.sleep(3000);
        }

    }
}
